package com.help.help.controller;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.alibaba.excel.EasyExcel;
import com.help.help.entity.AddressEntity;
import com.help.help.entity.UserEntity;
import com.help.help.service.UserService;
import com.help.help.util.ExceUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.help.help.entity.FileSEntity;
import com.help.help.service.FileSService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;

import javax.servlet.http.HttpServletResponse;


/**
 * 
 *
 * @author 小🌤
 * @email 1578442339@qq.com
 * @date 2021-01-07 15:41:11
 */
@RestController
@RequestMapping("/help/files")
public class FileSController {
    @Autowired
    private FileSService fileSService;
    @Autowired
    private UserService userService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = fileSService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String pages){
		FileSEntity fileS = fileSService.getById(pages);
		fileS.setUser(userService.getById(fileS.getUserId()));
    return R.ok().put("fileS", fileS);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody FileSEntity fileS){
		fileSService.save(fileS);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody FileSEntity fileS){
		fileSService.updateById(fileS);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] ids){
		fileSService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }
    /**
     * 导出
     * @param response
     * @param ids
     * @throws IOException
     */
    @RequestMapping("/updaloa")
    public void   upload(HttpServletResponse response, Integer[] ids) throws IOException {
        List<FileSEntity> list = fileSService.listByIds(Arrays.asList(ids));
        ExceUtil.out("文件管理导出信息", response);
        EasyExcel.write(response.getOutputStream(), FileSEntity.class).sheet("文件管理导出信息").doWrite(list);
    }
}
